package com.zjw.algorithm.reference_test;

import java.lang.ref.*;

public class WeakReferenceTest {

    public static void main(String[] args) {

        ReferenceQueue<Object> queue = new ReferenceQueue<>();
        Reference<Object> objectReference = new WeakReference<>(new Object(), queue);


        System.out.println("gc before:" + objectReference.get());


        Object sf = objectReference.get();
        System.gc();


//        try {
//            Reference<?> remove = queue.remove();
//            System.out.println("from queue :" + remove+"       r "+remove.get());
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }


        System.out.println("gc after:" + objectReference.get());
    }
}
